/*
 * @Author: c
 * @Date: 2024-01-15 17:33:03
 * @LastEditTime: 2024-02-25 12:57:37
 * @LastEditors: c
 * @Description:
 * @FilePath: \music-web-admin\src\api\minio\type.ts
 * https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// Copyright 2024 Administrator
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { UploadFile, UploadRawFile, UploadStatus } from "element-plus";
import { UploadAjaxError } from "element-plus/es/components/upload/src/ajax";
import { PictorialEnum } from "../picture/type";

export type UploadRequestHandler = (
  options: UploadRequestOptions
) => XMLHttpRequest | Promise<unknown>;

export interface UploadProgressEvent extends ProgressEvent {
  percent: number;
}

export interface UploadRequestOptions {
  action: string;
  method: string;
  data: Record<string, string | Blob | [string | Blob, string]>;
  filename: string;
  file: UploadRawFile;
  headers: Headers | Record<string, string | number | null | undefined>;
  onError: (evt: UploadAjaxError) => void;
  onProgress: (evt: UploadProgressEvent) => void;
  onSuccess: (response: any) => void;
  withCredentials: boolean;
}

export interface UploadFileDto extends UploadFile {
  // value: any;
  //创建者username
  creator?: string;

  //文件名称
  name: string;

  //原始文件
  raw?: UploadRawFile;

  //浏览器读取文件的时间戳

  uid: number;

  //上传进度
  percentage?: number;

  //文件的状态
  status: UploadStatus;

  //文件大小
  size: number;

  //文件的链接/本地的或者远程的
  url?: string;

  //文件最后修改时间
  lastModified: number;

  //文件mime类型
  type: string;

  //是否是公共访问的资源
  isPublic?: boolean;

  id?: string;

  picType?: PictorialEnum;

  webkitRelativePath: string;
}

export interface UploadVideoForm extends UploadFileDto {
  //封面图
  poster: string;
  //视频、图片高度
  height?: number;
  //视频、图片宽度
  width?: number;
  //视频时长
  duration?: number;
  //存储名称
  objectName?: string;
}

export type ProgressFunc = (
  loaded: number,
  total: number,
  index?: number
) => void;

export interface FileType {
  name?: string;
  file?: File;
}
